﻿using System;

namespace PageAdmin.Utils
{
    /// <summary>
    /// 表示可以自动执行的特性,只能用于方法上,而且方法必须为public类型的无参static方法。
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public class WebApiAttribute : Attribute
    {
        /// <summary>
        /// 名称。
        /// </summary>
        public string Name { get; }

        /// <summary>
        /// 是否检测签名，如果需要检测，则只能通过后台代码 WebAPI=new WebAPI()的方式调用。
        /// </summary>
        public bool CheckSignature { get; }

        /// <summary>
        /// 备注。
        /// </summary>
        public string Remark { get; }

        /// <summary>
        /// 请求类型，get,post
        /// </summary>
        public string HttpMethod { get; }

        /// <summary>
        /// 是否是公开的api，默认为true
        /// </summary>
        public bool IsPublic { get; }


        [Obsolete("此构造方法已经不推荐使用")]
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name">名称，必须保证唯一性</param>
        /// <param name="remark">备注</param>
        public WebApiAttribute(string name, string remark)
        {
            Name = name;
            Remark = remark;
            CheckSignature = true;
            HttpMethod = "";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name">Api名称，必须保证唯一性</param>
        /// <param name="httpMethod">get或post</param>
        /// <param name="checkSignature">是否检测签名</param>
        /// <param name="remark">备注</param>
        public WebApiAttribute(string name, string httpMethod, bool checkSignature, string remark)
        {
            Name = name;
            Remark = remark;
            CheckSignature = checkSignature;
            HttpMethod = httpMethod;
            this.IsPublic = true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name">Api名称，必须保证唯一性</param>
        /// <param name="httpMethod">get或post</param>
        /// <param name="checkSignature">是否检测签名</param>
        /// <param name="remark">备注</param>
        /// <param name="isPublic">是否公开</param>
        public WebApiAttribute(string name, string httpMethod, bool checkSignature, string remark, bool isPublic)
        {
            Name = name;
            Remark = remark;
            CheckSignature = checkSignature;
            HttpMethod = httpMethod;
            this.IsPublic = isPublic;
        }
    }
}
